<?php if($this->ticket !== false) { ?>
    <div class="ticket">
    	<div class="ticketHeader">
        	<table width="100%">
        		<tr>
        			<td width="130px"><strong>From:</strong></td>
        			<td><?php echo $this->ticket['from'] ?></td>
        		</tr>
        		<tr>
        			<td><strong>Subject:</strong></td>
        			<td><?php echo $this->ticket['subject'] ?></td>
        		</tr>
        		<tr>
        			<td><strong>Date:</strong></td>
        			<td><?php echo date('H:i:s d F Y', $this->ticket['created'])?></td>
        		</tr>
        		<tr>
        			<td><strong>Source:</strong></td>
        			<td><?php echo ucwords($this->ticket['source']) ?></td>
        		</tr>
        	</table>
    	</div>
    	
    	<div id="ticketActions">
            <ul>
                <li><a class="button altbutton" href="#" id="esculateTicketBtn" title="Esculate Ticket"><img class="icon16" src="/images/led-ico/user.png" style="padding-left: 6px;" />Esculate</a></li>
                <li><a class="button altbutton" href="#" id="addCommentBtn" title="Add Comment"><img class="icon16" src="/images/led-ico/note.png" style="padding-left: 6px;" />Comment</a></li>
                <li><a class="button altbutton" href="#" id="replyTicketBtn" title="Reply to Ticket"><img class="icon16" src="/images/led-ico/email.png" style="padding-left: 6px;" />Reply</a></li>
                <li><a class="button altbutton" href="#" id="completeTicketBtn" title="Complete Ticket"><img class="icon16" src="/images/led-ico/accept.png" style="padding-left: 6px;" />Complete</a></li>
            </ul>
        </div>
        
    	<div class="ticketComments">
    		<?php if(isset($this->ticket['comments']) && count($this->ticket['comments'])) { ?>
            	<?php foreach($this->ticket['comments'] as $comment) { ?>
                	<div class="ticketComment">
                		<div class="commentHeader">
                			<table width="100%">
                        		<tr>
                        			<td width="130px"><strong>Date:</strong></td>
                        			<td><?php echo date('H:i:s d F Y', $comment['created'])?></td>
                        		</tr>
                        		<tr>
                        			<td><strong>Source:</strong></td>
                        			<td><?php echo ucwords($comment['source']) ?></td>
                        		</tr>
                        	</table>
                		</div>
                		<div class="commentContent">
                			<?php echo $comment['comment'] ?>
                		</div>
                	</div>
            	<?php } ?>
        	<?php } else { ?>
        		<div class="ticketComment">
            		<div class="commentContent">
            			<table width="100%">
            				<tr>
            					<td style="vertical-align: middle"><img src="/images/fff/exclamation.png" /></td>
            					<td>
                        			This ticket contains no comments. This is probably due to an error in the system. <br />
                        			Should this continue, please contact the developer to investigate further.
                    			</td>
                			</tr>
            			</table>
            		</div>
            	</div>
        	<?php } ?>
    	</div>
    </div>
<?php } else { ?>
	<div class="ticket">
		<div class="ticketComment">
    		<div class="commentContent">
    			<table width="100%">
    				<tr>
    					<td style="vertical-align: middle"><img src="/images/fff/exclamation.png" /></td>
    					<td>
                			You have selected an invalid ticket to display. This is probably due to an error in the system. <br />
                			Should this continue, please contact the developer to investigate further.
            			</td>
        			</tr>
    			</table>
    		</div>
    	</div>
	</div>

<?php } ?>
<script>
	$("#addCommentBtn").click(function() {
		$("#commentTicketContent").html('');
		$("#commentTicketModal").parent("div.ui-dialog").css('height', '418px !important');
		$("#commentTicketContent").load('/backoffice/helpdesk/new-comment');
		$("#commentTicketModal").dialog('open');
        $("#commentTicketModal").parent("div.ui-dialog").css('top', '10px !important');
	});

	$("#esculateTicketBtn").click(function() {
	    $("#esculateTicketContent").html('');
		$("#esculateTicketModal").parent("div.ui-dialog").css('height', '488px !important');
		$("#esculateTicketContent").load('/backoffice/helpdesk/esculate-ticket');
		$("#esculateTicketModal").dialog('open');
        $("#esculateTicketModal").parent("div.ui-dialog").css('top', '10px !important');
	});
</script>